home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 049a / makearc.zip / MAKEARC.C next >
C/C++ Source or Header  |  1991-04-13  |  35KB  |  1,222 lines

  1. /* MakeArc copyright (c) 1991 by M. Kimes -- All Rights Reserved    */
  2. /* Version 3.00   You can use this freely.  Check with me before    */
  3. /* releasing modified executables or source, please (I'll probably  */
  4. /* allow it).  Exceptions:  Strict translation to foreign languages */
  5. /* and ports to other platforms (non-MS/DOS-OS/2)--go for it.       */
  6. /* Corrections, bug reports, etc. welcome.  Flames ignored by a     */
  7. /* master.                                                          */
  8.  
  9. /* The only real change between 2.05 and 3.00 is that 3.00 compiles */
  10. /* under MSC 6.0a                                                   */
  11.  
  12. #include <time.h>
  13. #include <dos.h>
  14. #include <stdio.h>
  15. #include <conio.h>
  16. #include <stdlib.h>
  17. #include <io.h>
  18. #include <fcntl.h>
  19. #include <ctype.h>
  20. #include <process.h>
  21. #include <string.h>
  22. #include <share.h>
  23. #include <sys/types.h>
  24. #include <sys/stat.h>
  25.  
  26.  
  27. typedef unsigned int _word;
  28.  
  29. /* Message header */
  30.  
  31. struct _msg {
  32.   char from[36];
  33.   char to[36];
  34.   char subj[72];
  35.   char date[20];    /* <--Did you notice the length of that? */
  36.   _word times;
  37.   _word dest;
  38.   _word orig;
  39.   _word cost;
  40.   _word orig_net;
  41.   _word dest_net;
  42.   int  msg_filler[4];    /* Differs by implementation; the heck with it */
  43.   _word reply;
  44.   _word attr;
  45.   _word up;
  46. };
  47.  
  48. /* Message attributes */
  49.  
  50. #define MSGPRIVATE 0x0001
  51. #define MSGCRASH   0x0002
  52. #define MSGREAD    0x0004
  53. #define MSGSENT    0x0008
  54. #define MSGFILE    0x0010
  55. #define MSGFWD     0x0020
  56. #define MSGORPHAN  0x0040
  57. #define MSGKILL    0x0080
  58. #define MSGLOCAL   0x0100
  59. #define MSGXX1     0x0200
  60. #define MSGXX2     0x0400
  61. #define MSGFRQ     0x0800
  62. #define MSGRRQ     0x1000
  63. #define MSGCPT     0x2000
  64. #define MSGARQ     0x4000
  65. #define MSGURQ     0x8000
  66.  
  67. /* Global flags and variables, w/ defaults */
  68.  
  69. unsigned char msgattach=0;       /* Make *.MSG attaches? */
  70. _word myzone=0;                  /* For our address */
  71. _word mynet=0;                   /* " */
  72. _word mynode=0;                  /* " */
  73. _word mypoint=0;                 /* " */
  74. char configfile[133]="MAKEARC.CFG";    /* Config file to read */
  75. char root[128]="";               /* 'Root' outbound dir */
  76. char outbound[133]="";           /* Extended outbound dir */
  77. char netdir[128]="";             /* Net msg directory if *.MSG attaches */
  78. char arccmd[133]="";             /* Default archive command */
  79. unsigned char alltype=0;         /* Default mail type */
  80. unsigned char didbreak=0;        /* CTRL-BREAK flag */
  81. char schedtag[128]="";           /* Schedule tag */
  82. _word lines=0;                   /* For debug info */
  83. unsigned char debug=0;           /* debug on? */
  84. unsigned char more=0;            /* more on? */
  85. unsigned char usingbink=0;       /* Use BINKLEY.CFG? */
  86. _word rzone=0;                   /* For routing */
  87. _word rnet=0;                    /* " */
  88. _word rnode=0;                   /* " */
  89. _word rpoint=0;                  /* " */
  90.  
  91. /* Function definitions */
  92.  
  93. char     _fastcall spawnit (char *a);
  94. char     _fastcall check_4flo (_word zone,_word net,_word node,_word point);
  95. char *   _fastcall stristr (char *t, char *s);
  96. void     _cdecl  deinit(void);
  97. void     _fastcall say_error (long lastpos,FILE *fp);
  98. int      _fastcall makearc (char *arcfile,char *pktfile,char *origpkt,char *outbound);
  99. _word    _fastcall makeflo(_word zone,_word net,_word node,_word point,char *sendfile,char type);
  100. _word    _fastcall makemessage (_word zone,_word net,_word node,_word point,char *sendfile,char type);
  101. void     _fastcall next_name(char *);
  102. void     _fastcall make_poll (char *line,long lastpos,FILE *fp);
  103. FILE *   _fastcall analyze(char *);
  104. char *   _fastcall arcname(_word,_word);
  105. char *   _fastcall filename(_word,_word);
  106. char *   _fastcall fidodate(void);
  107. char *   _fastcall lstrip(char *);
  108. char *   _fastcall rstrip(char *);
  109. char *   _fastcall stripcr(char *);
  110. void     _fastcall moveit (struct FILEFINDBUF *f, char *myoutbound, char *outbound, char type, char archive,_word net,_word node,_word fromzone);
  111. void     _fastcall move_prep(char *line,long lastpos,FILE *fp);
  112. void     _fastcall change_mail(char *line,long lastpos,FILE *fp);
  113. long     _fastcall make_msgid(void);
  114. char *   _fastcall find_sched(FILE *fp,char *schedtag,int wholefile);
  115. char *   _fastcall skip_white(char *);
  116. char *   _fastcall skip_nonwhite(char *);
  117. char *   _fastcall to_delim(char *,char *);
  118.  
  119. /* ID stuff */
  120.  
  121. #define MAKEVER "3.00"
  122.  
  123. #define PID_ID "MA 3.00"
  124.  
  125. #define BETA yep
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132. void _cdecl main (int argc,char *argv[]) {
  133.  
  134.     FILE     *fp;
  135.     struct    find_t f,d;
  136.     time_t  t,starttime;
  137.     char     s[133],s2[133],pktfile[133],arcfile[133],origpkt[13];
  138.     _word    hisnode,hisnet,hiszone=0,hispoint=0;
  139.     char     *p,*pp;
  140.     char     new,type=0,lastlevel=0;
  141.     char     temp[34];
  142.     long     t_counter=0,lastpos;
  143.     char     tempcmd[80]="";
  144.     char     doingnet,doingdomain,doingzone;
  145.     int      founddir,rc;
  146.  
  147.   /* Big, ugly main() function.  What do you expect from an amateur ex-BASIC
  148.      programmer, anyway? */
  149.  
  150.   starttime=time(NULL);  /* For length-of-run timer */
  151.  
  152.   /* Display program title and copyright info */
  153.  
  154.   fprintf(stderr,"\n\nMAKEARC v%s  %s  %s   copyright (c) 1990/91 by M. Kimes",
  155.     MAKEVER,__DATE__,__TIME__);
  156.  
  157. #ifdef BETA
  158.   fprintf(stderr," -- Beta");
  159. #endif
  160.  
  161.   fprintf(stderr,"\n");
  162.  
  163.   /* Nothing on command line--let 'em know help is available. */
  164.  
  165.   if(argc==1) fprintf(stderr,"I archive packets and make attaches for them.  ? for help.\n");
  166.  
  167.   /* First arg is ? so give 'em the help and stop */
  168.  
  169.   if(argc>1 && *argv[1]=='?') {
  170.         fprintf(stderr,"\nGimme a config file, default MAKEARC.CFG.  A schedule tag is optional.\n"
  171.                "If environment variable MAKECFG is set, I'll use that value to find the config\n"
  172.                "file instead.  If MAKESCHD is set, I'll use that value for a schedule tag.\n"
  173.                "Examples: (assumes environment variables not used)\n"
  174.                "MAKEARC (defaults to MAKEARC.CFG, no schedule tag)\n"
  175.                "MAKEARC ALTMAKE.CFG (defaults to no schedule tag)\n"
  176.                "MAKEARC MAKEARC2.CFG MAILTIME (config file MAKEARC2.CFG, schedule tag MAILTIME)\n"
  177.                "MAKEARC MAKEIT.CFG AFTERMAIL D (startup with debug on)\n"
  178.                "MAKEARC MAKE2.CFG BEFOREMAIL M (startup with more info on)\n"
  179.                "\nYou probably shouldn't use points *at all* when dealing with the outbound.\n"
  180.                "You should not route Crash mail.\n\n"
  181.                "In the configuration file, list the following:\n"
  182.                "SCHED <any_text> (A schedule tag, not required unless you use them)\n"
  183.                "ADDRESS <zone:net/node[.point]> (Your address--use point only if\n"
  184.                "                                 your mailer understands it)\n"
  185.                "OUTBOUND <main outbound directory>\n"
  186.                "NETDIR <netmail directory> (use with MSG below)\n"
  187.                "MSG (means create *.MSG attaches instead of *.FLO attaches)\n"
  188.                "FLO (opposite of MSG, default)\n"
  189.                " [Any Key]");
  190.                getch();
  191.                fprintf(stderr,"\b\b\b\b\b\b\b\b\b\b"
  192.                "ARCCMD <default archive command>\n"
  193.                "ALLTYPE <default mail type: Crash, Hold, etc.>\n"
  194.                "ROUTE <address> (routes all following mail to <address> until\n"
  195.                "                 next ROUTE command (ROUTE 0:0/0 cancels))\n"
  196.                "DOMAIN <main outbound dir> <type> <arc cmd>\n"
  197.                " (Do a pass through outbound directories.  Arguments are optional.\n"
  198.                "  Defaults will be used if not present.  Note that giving an outbound\n"
  199.                "  directory here performs an implicit OUTBOUND command)\n"
  200.                "ZONE <zone#>: <mail type> <arc cmd> (Do a pass through <zone#>)\n"
  201.                "NET <zone#>:<net#>/ <mail type> <arc cmd> (do a pass through <net#>)\n"
  202.                "MOVE <zone#> <address> <mail type> (move mail from <zone#> to another)\n"
  203.                "CHANGE <address> <mail type> (change all mail to <address> to <mail type>)\n"
  204.  
  205. /*
  206.             Commented this out; too much damn trouble.
  207.             Code (doesn't work) is still there.
  208. */
  209.  
  210.  
  211. /*
  212.                " (alternate: CHANGE ALL [<ZONE> <#>] <type> (change all mail to <type>)\n"
  213. */
  214.  
  215.                "POLL <address> [<password>] (force a call to <address> by creating *.CLO)\n"
  216.                "SPAWN <string> (spawn <string>...use COMMAND.COM /c for batch files)\n"
  217.                "IFERRORLEVEL <!<>=> <#> <command> (process <command> if last ERRORLEVEL\n"
  218.                "                                   from SPAWN command satisfies compare)\n"
  219.                "<zone#>:<net#>/<node#> <mail type: Crash, Hold, etc.> <archive command>\n"
  220.                " [Any Key]");
  221.                getch();
  222.                fprintf(stderr,"\b\b\b\b\b\b\b\b\b\b"
  223.                "END (means stop now and do pass through your zone)\n"
  224.                "BREAK (means don't do pass through your zone--stop NOW)\n"
  225.                "GOTO <schedtag> (jump to schedule tag <schedtag>)\n"
  226.                "IFINTIME <hh:mm:ss> <hh:mm:ss> <command> (process <command> if in timeframe)\n"
  227.                "IFDOW <#> <command> (process <command> if <#>=day of week (1-7 from Sunday))\n"
  228.                "IFDOM <#> <command> (process <command> if <#>=day of month (1-31))\n"
  229.                "IFMON <#> <command> (process <command> if <#>=month (1-12))\n"
  230.                "DEBUG (means get verbose, show *everything*)\n"
  231.                "MORE (means more info, but don't get totally ridiculous)\n");
  232.                exit(0);
  233.   }
  234.  
  235.   /* Use command line arguments if available */
  236.  
  237.   if (argc>1) strcpy(configfile,argv[1]);
  238.   if(argc>2) strcpy(schedtag,argv[2]);
  239.   if(argc>3 && toupper(*argv[3])=='D') debug=1;
  240.   if(argc>3 && toupper(*argv[3])=='M') more=1;
  241.  
  242.   /* Try to find our environment variables (overrides command line) */
  243.  
  244.   p=getenv("MAKECFG");
  245.   if(*p && p) strcpy(configfile,getenv("MAKECFG"));
  246.   p=getenv("MAKESCHD");
  247.   if(*p && p) strcpy(schedtag,getenv("MAKESCHD"));
  248.  
  249.   if(_dos_findfirst(configfile,0,&f)) {
  250.  
  251.     /* Couldn't find configfile; look for BINKLEY environment variable
  252.        and then BINKLEY.CFG */
  253.  
  254.     if(getenv("BINKLEY")) {
  255.         strcpy(configfile,getenv("BINKLEY"));
  256.         if(configfile[strlen(configfile)-1]=='\\')
  257.             configfile[strlen(configfile)-1]=0;
  258.         strcat(configfile,"\\BINKLEY.CFG");
  259.     }
  260.     else strcpy(configfile,"BINKLEY.CFG");
  261.   }
  262.  
  263.   if(stristr(configfile,"BINKLEY.CFG"))
  264.     usingbink=1;              /* Look for APPLICATIONs */
  265.  
  266.   fp=analyze(configfile);    /* Open file, find schedule tag, etc. */
  267.  
  268.   atexit(deinit);            /* Removes marker file */
  269.  
  270.   fclose(fopen("MAKEARC.RUN","w"));    /* Marker file; "I'm running!" */
  271.  
  272.   while(!feof(fp)) {                    /* Process config file--main loop */
  273.     lastpos=ftell(fp);
  274.     strcpy(outbound,root);                /* Reset outbound variable */
  275.     doingnet=doingzone=doingdomain=0;    /* Reset special condition flags */
  276.     if(!hiszone) hiszone=myzone;
  277.     if(!fgets(s,133,fp)) goto DoneWithFile;
  278.     lines++;                            /* Line counter for error msgs */
  279.     if(debug) printf("%u. %s",lines,s);    /* Display line if debug on */
  280.     if(p=(strchr(s,';'))) *p=0;            /* Lose trailing comments */
  281.     stripcr(s);                            /* Lose cr/lf */
  282.     lstrip(s);                            /* Lose leading spaces */
  283.     rstrip(s);                            /* Lose trailing spaces */
  284.     if(!*s || *s==';') continue;        /* Skip blank or comment lines */
  285.     while(p=(strchr(s,'\t'))) *p=' ';    /* Get rid of tabs */
  286.     lstrip(s);                            /* Strip extraneous spaces */
  287.     rstrip(s);
  288.     p=s;
  289.  
  290. /* This label used to merge back into the stream after IFERRORLEVEL */
  291.  
  292. AfterERRORLEVEL:
  293.  
  294.     if(!strnicmp(p,"OUTBOUND ",9) || !strnicmp(p,"HOLD ",5)) {
  295.         if(toupper(*p)=='O')p+=9;        /* Main outbound directory */
  296.         else p+=5;
  297.         lstrip(p);
  298.         while(pp=(strchr(p,'/'))) *pp='\\';   /* Convert slashes to backslashes */
  299.         strncpy(outbound,p,80);
  300.         outbound[79]=0;
  301.         if(outbound[strlen(outbound)-1]=='\\') outbound[strlen(outbound)-1]=0;
  302.         strcpy(root,outbound);
  303.         p=strrchr(root,'\\');
  304.         if(p) {
  305.             p++;
  306.             printf("Current Domain: `%s'\n",p);
  307.         }
  308.         if(debug || more) printf("Outbound dir=`%s'\n",root);
  309.         continue;
  310.     }
  311.  
  312.     else if(!strnicmp(p,"NETDIR ",7) || !strnicmp(p,"NETMAIL ",8)) {
  313.         if(toupper(p[7])=='L') p+=8;    /* Net directory (w/ MSG) */
  314.         else p+=7;
  315.         lstrip(p);
  316.         while(pp=(strchr(p,'/'))) *pp='\\';   /* Convert slashes to backslashes */
  317.         strncpy(netdir,p,80);
  318.         netdir[79]=0;
  319.         if(netdir[strlen(netdir)-1]=='\\') netdir[strlen(netdir)-1]=0;
  320.         if(debug || more)printf("Net dir=`%s'\n",netdir);
  321.         continue;
  322.     }
  323.  
  324.     else if(!strnicmp(p,"ADDRESS ",8)) {    /* Our address */
  325.         p+=8;
  326.         lstrip(p);
  327.         p=strtok(p,":");
  328.         if(!p) {
  329.             fprintf(stderr,"\nMissing Zone\n");
  330.             say_error(lastpos,fp);
  331.             continue;
  332.         }
  333.         myzone=(unsigned int)atol(p);
  334.         if(!myzone) {
  335.             fprintf(stderr,"\nZero Zone\n");
  336.             say_error(lastpos,fp);
  337.             continue;
  338.         }
  339.         p=strtok(0,"/");
  340.         if(!p) {
  341.             fprintf(stderr,"\nMissing Net\n");
  342.             say_error(lastpos,fp);
  343.             continue;
  344.         }
  345.         mynet=(unsigned int)atol(p);
  346.         if(!mynet) {
  347.             fprintf(stderr,"\nZero Net\n");
  348.             say_error(lastpos,fp);
  349.             continue;
  350.         }
  351.         p=strtok(0,".@ ");
  352.         if(!p) {
  353.             fprintf(stderr,"\nMissing Node\n");
  354.             say_error(lastpos,fp);
  355.             continue;
  356.         }
  357.         mynode=(unsigned int)atol(p);
  358.         p=strtok(0,"@ ");
  359.         if(!p) mypoint=0;
  360.         else mypoint=(unsigned int)atol(p);
  361.         if(debug || more) {
  362.             if(mypoint)printf("Address=`%u:%u/%01u.%01u'\n",myzone,mynet,mynode,mypoint);
  363.             else printf("Address=`%u:%u/%01u'\n",myzone,mynet,mynode);
  364.         }
  365.         continue;
  366.     }
  367.  
  368.     else if(usingbink) {            /* Check for Binkley.cfg APPLICATIONs */
  369.         if(strnicmp(p,"APPLICATION MAKEARC ",20)) continue; /* Not ours */
  370.         p+=20;
  371.         lstrip(p);
  372.     }
  373.  
  374.     else if(!stricmp(p,"MORE")) {    /* Toggle more */
  375.         more=1-more;
  376.         if(debug) printf("More ON\n");
  377.         else printf("More OFF\n");
  378.         continue;
  379.     }
  380.  
  381.     else if(!stricmp(p,"DEBUG")) {    /* Toggle debug */
  382.         debug=1-debug;
  383.         if(debug) printf("Debug ON\n");
  384.         else printf("Debug OFF\n");
  385.         continue;
  386.     }
  387.  
  388.     else if(!strnicmp(p,"POLL ",5)) {    /* Create empty poll *.CLO file */
  389.         p+=5;
  390.         make_poll(p,lastpos,fp);
  391.         continue;
  392.     }
  393.  
  394.     else if(!strnicmp(p,"SCHED ",6)) continue;    /* Skip schedule tags */
  395.  
  396.     else if(!strnicmp(p,"ARCCMD ",7)) {    /* Default archiver command */
  397.         p+=7;
  398.         lstrip(p);
  399.         strncpy(arccmd,p,80);
  400.         arccmd[79]=0;
  401.         strcpy(tempcmd,arccmd);
  402.         if(debug || more)printf("Archiver command=`%s <arcname> <pktname>'\n",arccmd);
  403.         continue;
  404.     }
  405.  
  406.     else if(!stricmp(p,"MSG")) {    /* Make MSG attaches instead of FLO */
  407.         msgattach=1;
  408.         if(debug || more)printf("Making *.MSG attaches\n");
  409.         continue;
  410.     }
  411.  
  412.     else if(!stricmp(p,"FLO")) {    /* Opposite of MSG */
  413.         msgattach=0;
  414.         if(debug || more)printf("Making *.?LO attaches\n");
  415.         continue;
  416.     }
  417.  
  418.     else if(!strnicmp(p,"ALLTYPE ",8)) {    /* Default mail type */
  419.         p+=8;
  420.         lstrip(p);
  421.         alltype=toupper(*p);
  422.         if(debug || more)printf("Default mail type=`%c'\n",alltype);
  423.         continue;
  424.     }
  425.  
  426.     else if(!strnicmp(p,"SPAWN ",6)) {        /* Do external command */
  427.         p+=6;
  428.         lstrip(p);
  429.         printf("SPAWNing `%s'\n",p);
  430.         lastlevel=spawnit(p);
  431.         continue;
  432.     }
  433.  
  434.     else if(!strnicmp(p,"IFERRORLEVEL ",13)) {    /* Respond to ERRORLEVEL */
  435.  
  436.         char oper;
  437.         char level;
  438.  
  439.         p+=13;
  440.         lstrip(p);
  441.         oper=*p;
  442.         p++;
  443.         lstrip(p);
  444.         level=(char)atoi(p);
  445.         p=skip_nonwhite(p);
  446.         lstrip(p);
  447.         if(oper=='!' && lastlevel!=level) {
  448.             printf("ERRORLEVEL match...\n");
  449.             goto AfterERRORLEVEL;
  450.         }
  451.         else if(oper=='>' && lastlevel>level) {
  452.             printf("ERRORLEVEL match...\n");
  453.             goto AfterERRORLEVEL;
  454.         }
  455.         else if(oper=='<' && lastlevel<level) {
  456.             printf("ERRORLEVEL match...\n");
  457.             goto AfterERRORLEVEL;
  458.         }
  459.         else if(lastlevel==level) {
  460.             printf("ERRORLEVEL match...\n");
  461.             goto AfterERRORLEVEL;
  462.         }
  463.         if(debug || more) printf("ERRORLEVEL didn't match...\n");
  464.         continue;
  465.     }
  466.  
  467.     else if(!strnicmp(p,"IFINTIME ",9)) {
  468.  
  469.         long tt1,tt2,tt3;
  470.         struct tm *tt;
  471.  
  472.         p+=9;
  473.         lstrip(p);
  474.         tt1=(atol(p) * 3600L);
  475.         p=to_delim(p,":");
  476.         if(*p==':')p++;
  477.         tt1+=(atol(p) * 60L);
  478.         p=to_delim(p,":");
  479.         if(*p==':')p++;
  480.         tt1+=atol(p);
  481.         p=skip_nonwhite(p);
  482.         lstrip(p);
  483.         tt2=(atol(p) * 3600L);
  484.         p=to_delim(p,":");
  485.         if(*p==':')p++;
  486.         tt2+=(atol(p) * 60L);
  487.         p=to_delim(p,":");
  488.         if(*p==':')p++;
  489.         tt2+=atol(p);
  490.         p=skip_nonwhite(p);
  491.         lstrip(p);
  492.         tt3=time(NULL);
  493.         tt=localtime(&tt3);
  494.         tt3=(long)tt->tm_hour * 3600L;
  495.         tt3+=(long)tt->tm_min * 60L;
  496.         tt3+=(long)tt->tm_sec;
  497.         if (tt3<tt1 || tt3>tt2) continue;    /* Not in timeframe */
  498.         goto AfterERRORLEVEL;
  499.     }
  500.  
  501.     else if(!strnicmp(p,"IFDOW ",6)) {    /* If day of week (1-7) from Sun */
  502.  
  503.         struct tm *tt;
  504.         long tl;
  505.         int dow;
  506.  
  507.         p+=6;
  508.         lstrip(p);
  509.         dow=atoi(p);
  510.         p=skip_nonwhite(p);
  511.         lstrip(p);
  512.         tl=time(NULL);
  513.         tt=localtime(&tl);
  514.         if(tt->tm_wday+1 != dow) continue;    /* Not right day of week */
  515.         goto AfterERRORLEVEL;
  516.     }
  517.  
  518.     else if(!strnicmp(p,"IFMONTH ",8)) {    /* If month (1-12) */
  519.  
  520.         struct tm *tt;
  521.         long tl;
  522.         int mon;
  523.  
  524.         p+=8;
  525.         lstrip(p);
  526.         mon=atoi(p);
  527.         p=skip_nonwhite(p);
  528.         lstrip(p);
  529.         tl=time(NULL);
  530.         tt=localtime(&tl);
  531.         if(tt->tm_mon+1 != mon) continue;    /* Not right month */
  532.         goto AfterERRORLEVEL;
  533.     }
  534.  
  535.     else if(!strnicmp(p,"IFDOM ",6)) {    /* If day of month (1-31) */
  536.  
  537.         struct tm *tt;
  538.         long tl;
  539.         int dom;
  540.  
  541.         p+=6;
  542.         lstrip(p);
  543.         dom=atoi(p);
  544.         p=skip_nonwhite(p);
  545.         lstrip(p);
  546.         tl=time(NULL);
  547.         tt=localtime(&tl);
  548.         if(tt->tm_mday != dom) continue;    /* Not right day of month */
  549.         goto AfterERRORLEVEL;
  550.     }
  551.  
  552. /* Have pity; break up the if...else if chain */
  553.  
  554.     if(!stricmp(p,"BREAK")) {                /* No global pass through our zone */
  555.         if(debug || more) printf("BREAK encountered.\n");
  556.         break;
  557.     }
  558.  
  559.     else if(!stricmp(p,"END")) {            /* Global then end */
  560.         if(debug || more) printf("END encountered.\n");
  561.         goto DoneWithFile;
  562.     }
  563.  
  564.     else if(!strnicmp(p,"GOTO ",5)) {        /* Jump to a schedule tag */
  565.         p+=5;
  566.         lstrip(p);
  567.         printf("Branching to SCHED tag `%s'\n",p);
  568.         if(!find_sched(fp,p,1)) exit(10);
  569.         continue;
  570.     }
  571.  
  572.     else if(!strnicmp(p,"ROUTE ",6)) {  /* Misdirect mail :-) */
  573.         p+=6;
  574.         p=strtok(p,":");
  575.         if(!p) {
  576.             fprintf(stderr,"\nMissing Zone\n");
  577.             say_error(lastpos,fp);
  578.             continue;
  579.         }
  580.         p=skip_white(p);
  581.         rzone=(unsigned int)atol(p);
  582.         p=strtok(0,"/");
  583.         if(!p) {
  584.             fprintf(stderr,"\nMissing Net\n");
  585.             say_error(lastpos,fp);
  586.             continue;
  587.         }
  588.         rnet=(unsigned int)atol(p);
  589.         p=strtok(0,".;\n");
  590.         if(!p) {
  591.             fprintf(stderr,"\nMissing Node\n");
  592.             say_error(lastpos,fp);
  593.             continue;
  594.         }
  595.         rnode=(unsigned int)atol(p);
  596.         p=strtok(0,";\n");
  597.         if(!p) rpoint=0;
  598.         else rpoint=(unsigned int)atol(p);
  599.         if(rzone && !rnet) rzone=0;
  600.         if(debug || more) {
  601.             if(!rpoint)printf("Route To=`%u:%u/%01u.%01u'\n",rzone,rnet,rnode,rpoint);
  602.             else printf("Route To=`%u:%u/%01u'\n",rzone,rnet,rnode);
  603.         }
  604.         continue;
  605.     }
  606.  
  607.     else if(!strnicmp(p,"MOVE ",5)) {    /* Move mail from outbound->outbound */
  608.         p+=5;
  609.         lstrip(p);
  610.         move_prep(p,lastpos,fp);
  611.         continue;
  612.     }
  613.  
  614.     else if(!strnicmp(p,"CHANGE ",6)) {    /* Change mail's type */
  615.         p+=6;
  616.         lstrip(p);
  617.         change_mail(p,lastpos,fp);
  618.         continue;
  619.     }
  620.  
  621.     else if(!strnicmp(p,"DOMAIN",6)) {     /* Make pass through a domain */
  622.  
  623.         char *ppp;
  624.  
  625.         p+=6;
  626.         lstrip(p);
  627.         if(*p) {
  628.             ppp=skip_nonwhite(p);
  629.             if(*ppp) {
  630.                 *ppp=0;
  631.                 ppp++;
  632.                 ppp=skip_white(ppp);
  633.             }
  634.             while(pp=(strchr(p,'/')))
  635.                 *pp='\\';   /* Convert slashes to backslashes */
  636.             strncpy(outbound,p,80);
  637.             outbound[79]=0;
  638.             if(outbound[strlen(outbound)-1]=='\\')
  639.                 outbound[strlen(outbound)-1]=0;
  640.             strcpy(root,outbound);
  641.             if(debug || more) printf("Outbound dir=`%s'\n",root);
  642.             if(*ppp) {
  643.                 type=toupper(*ppp);
  644.                 ppp=skip_nonwhite(ppp);
  645.                 ppp=skip_white(ppp);
  646.                 if(*ppp) {
  647.                     strcpy(arccmd,ppp);
  648.                 }
  649.                 else strcpy(arccmd,tempcmd);
  650.             }
  651.             else {
  652.                 type=alltype;
  653.                 strcpy(arccmd,tempcmd);
  654.             }
  655.         }
  656.         else {
  657.             type=alltype;
  658.             strcpy(arccmd,tempcmd);
  659.         }
  660.         p=strrchr(root,'\\');
  661.         if(p)p++;
  662.         else p="Current";
  663.         printf("Domain `%s'",p);
  664.         if(rzone) printf(" -=> %u:%u.%u",rzone,rnet,rnode);
  665.         printf("\n");
  666.         doingdomain=1;
  667.     }
  668.  
  669.     else {
  670.         if(!strnicmp(p,"NET ",4)) {    /* Make a pass through a whole net */
  671.             doingnet=1;
  672.             p+=4;
  673.             lstrip(p);
  674.         }
  675.  
  676.         else if(!strnicmp(p,"ZONE ",5)) {    /* Do a global pass through a zone */
  677.             p+=5;
  678.             lstrip(p);
  679.             doingzone=1;
  680.         }
  681.  
  682.         /* Otherwise it's a full address to send to */
  683.  
  684.         p=strtok(p,":");
  685.         if(!p) {
  686.             fprintf(stderr,"\nMissing Zone\n");
  687.             say_error(lastpos,fp);
  688.             continue;
  689.         }
  690.         hiszone=(unsigned int)atol(p);
  691.         if(!hiszone) {
  692.             fprintf(stderr,"\nZero Zone\n");
  693.             say_error(lastpos,fp);
  694.             continue;
  695.         }
  696.         if(!doingzone) {
  697.             p=strtok(0,"/");
  698.             if(!p) {
  699.                 fprintf(stderr,"\nMissing Net\n");
  700.                 say_error(lastpos,fp);
  701.                 continue;
  702.             }
  703.             hisnet=(unsigned int)atol(p);
  704.             if(!hisnet) {
  705.                 fprintf(stderr,"\nZero Net\n");
  706.                 say_error(lastpos,fp);
  707.                 continue;
  708.             }
  709.             if(!doingnet) {
  710.                 p=strtok(0," ;");
  711.                 if(!p) {
  712.                     fprintf(stderr,"\nMissing Node\n");
  713.                     say_error(lastpos,fp);
  714.                     continue;
  715.                 }
  716.                 hisnode=(unsigned int)atol(p);
  717.                 if(strchr(p,'.')) {
  718.                     p=strchr(p,'.');
  719.                     p++;
  720.                     hispoint=(unsigned int)atol(p);
  721.                 }
  722.                 else hispoint=0;
  723.             }
  724.             else {
  725.                 hisnode=0;
  726.                 hispoint=0;
  727.             }
  728.         }
  729.         else {
  730.             hisnet=0;
  731.             hisnode=0;
  732.             hispoint=0;
  733.         }
  734.         p=strtok(0," ;");
  735.         if(p) {
  736.             type=toupper(*p);
  737.         }
  738.         else type=alltype;
  739.         p=strtok(0,";\n");
  740.         if(p) {
  741.             lstrip(p);
  742.             rstrip(p);
  743.             strcpy(arccmd,p);
  744.         }
  745.         else strcpy(arccmd,tempcmd);
  746.  
  747.         if(!doingnet && !doingzone) {
  748.             sprintf(s,"%s\\%04x%04x.?UT",outbound,hisnet,hisnode); /* Find just this one guy for now */
  749.             if(!hispoint)printf("%u:%u/%01u",hiszone,hisnet,hisnode); /* Tell console */
  750.             else printf("%u:%u/%01u.%01u",hiszone,hisnet,hisnode,hispoint);
  751.         }
  752.         else if(doingnet) {
  753.             sprintf(s,"%s\\%04x*.?UT",outbound,hisnet); /* Find anyone in net */
  754.             printf("Net %u:%u",hiszone,hisnet);
  755.         }
  756.         else {
  757.             sprintf(outbound,"%s.%03x",root,hiszone);
  758.             sprintf(s,"%s\\*.?UT",outbound);
  759.             printf("Zone %u (%s)",hiszone,outbound);
  760.         }
  761.         if(rzone) printf(" -=> %u:%u/%u",rzone,rnet,rnode);
  762.         printf("\n");
  763.     }
  764.  
  765. /* The following label is used to goto for the default pass through
  766.    the default zone (unless BREAK is encountered) at termination. */
  767.  
  768. OneMoreTime:
  769.  
  770.     if(doingdomain) sprintf(s2,"%s.*",root); /* Special find-the-outbound */
  771.     else strcpy(s2,outbound);                /* code. */
  772.     do {
  773.         founddir=_dos_findfirst(s2,16,&d);
  774.     } while(!founddir && !(d.attrib & 16));
  775.  
  776.     if(founddir && !doingdomain) {    /* No outbound directory?  Uh oh... */
  777.         fprintf(stderr,"\nOutbound directory %s doesn't seem to exist.\n",s2);
  778.     }
  779.  
  780.     while(!founddir) {    /* Loop once for anything but DOMAIN */
  781.     p=strrchr(d.name,'.');
  782.         if(p) sprintf(outbound,"%s%s",root,p);
  783.         else strcpy(outbound,root);
  784.  
  785.         if(doingdomain) {    /* Get zone # from outbound extension */
  786.             hiszone=0;
  787.             sprintf(s,"%s\\*.?UT",outbound); /* Setup to find any pkt in zone */
  788.             p=strrchr(outbound,'.');
  789.             if(p) {
  790.                 p++;
  791.                 strncpy(temp,p,3);
  792.                 hiszone=(_word)strtol(temp,&p,16);
  793.             }
  794.             if(!hiszone)hiszone=myzone;
  795.             printf(" Zone %u",hiszone);  /* and display it */
  796.             if(rzone) printf(" -=> %u:%u/%u",rzone,rnet,rnode);
  797.             printf("\n");
  798.             if(debug || more) printf(" Outbound: `%s'\n",outbound);
  799.         }
  800.  
  801.         while(!_dos_findfirst(s,0,&f)) {     /* Never leave one after processing */
  802.             if(didbreak) {            /* CTRL-BREAK pressed; outta here */
  803.                 if(fp)fclose(fp);
  804.                 fprintf(stderr,"\nExitting in response to user break.\x1b[0m\n");
  805.                 exit(99);
  806.             }
  807.             if(hiszone!=myzone) sprintf(outbound,"%s.%03x",root,hiszone);
  808.         strcpy(pktfile,f.name);
  809.             strcpy(origpkt,strupr(pktfile));
  810.             strncpy(temp,pktfile,4);
  811.             temp[4]=0;
  812.             p=temp;
  813.             hisnet=(_word)strtol(temp,&p,16);
  814.             strncpy(temp,&pktfile[4],4);
  815.             temp[4]=0;
  816.             p=temp;
  817.             hisnode=(_word)strtol(temp,&p,16);
  818.         sprintf(pktfile,"%s\\%s",outbound,f.name);
  819.             if(rzone) {
  820.                 strcpy(arcfile,arcname(rnet,rnode));
  821.             }
  822.             else {
  823.                 strcpy(arcfile,arcname(hisnet,hisnode));
  824.             }
  825.             strcat(arcfile,".*");
  826.             t=time(NULL);
  827.             ltoa(t,temp,36);
  828.             sprintf(s2,"%s\\%6.6s%02hx.PKT",outbound,temp,(char)t_counter++);
  829.             rename(pktfile,s2);
  830.             strcpy(pktfile,s2);
  831.             if(rzone && rzone!=myzone) {
  832.                 sprintf(outbound,"%s.%03x",root,rzone);
  833.             }
  834.             sprintf(s2,"%s\\%s",outbound,arcfile);
  835.         if(_dos_findfirst(s2,0,&f)) {
  836.                 if(rzone) {
  837.                     sprintf(arcfile,"%s\\%s.MO1",outbound,arcname(rnet,rnode));
  838.                 }
  839.                 else {
  840.                     sprintf(arcfile,"%s\\%s.MO1",outbound,arcname(hisnet,hisnode));
  841.                 }
  842.                 new=1;
  843.             }
  844.             else {
  845.         sprintf(arcfile,"%s\\%s",outbound,f.name);
  846.                 new=0;
  847.                 if(f.size==0L) {      /* Just a marker file */
  848.                     new=1;
  849.                     unlink(arcfile);
  850.                     p=strrchr(arcfile,'.');
  851.                     if(!p) {        /* Invalid filename */
  852.                         strcat(arcfile,".MO1");
  853.                     }
  854.                     else {
  855.                         arcfile[strlen(arcfile)-1]++;
  856.                         if(!isdigit(arcfile[strlen(arcfile)-1])) {
  857.                             next_name(p);    /* Inc filename */
  858.                         }
  859.                     }
  860.                 }
  861.             }
  862.             if(new)printf("Making ");
  863.             else printf("Adding to ");
  864.             if(hispoint)printf("archive %s for %u:%u/%01u.%01u...\n",arcfile,hiszone,hisnet,hisnode,hispoint);
  865.             else printf("archive %s for %u:%u/%01u...\n",arcfile,hiszone,hisnet,hisnode);
  866.             if(rzone) {
  867.                 if(rpoint)printf("Routing it to %u:%u/%01u\n",rzone,rnet,rnode,rpoint);
  868.                 else printf("Routing it to %u:%u/%01u\n",rzone,rnet,rnode);
  869.             }
  870.             rc=makearc(arcfile,pktfile,origpkt,outbound);
  871.             if(!rc) { /* Archiver error */
  872. MakeFloAnyway:
  873.               if(new) {
  874.                 p=strrchr(origpkt,'.');
  875.                 if(!p)p=".F";
  876.                 strcpy(s2,&p[1]);
  877.                 if(toupper(*s2)=='O') *s2='F';
  878.                 if(type) *s2=type;
  879.                 else if (alltype) *s2=alltype;
  880.                 if(msgattach) {
  881.                     if(rzone) makemessage(rzone,rnet,rnode,rpoint,arcfile,*s2);
  882.                     else makemessage(hiszone,hisnet,hisnode,hispoint,arcfile,*s2);
  883.                 }
  884.                 else {
  885.                     if(rzone) makeflo(rzone,rnet,rnode,rpoint,arcfile,*s2);
  886.                     else makeflo(hiszone,hisnet,hisnode,hispoint,arcfile,*s2);
  887.                 }
  888.               }
  889.               else if(!msgattach) {   /* Quick&dirty check for orphaned archives (Flow files only) */
  890.                   if(rzone) new=check_4flo(rzone,rnet,rnode,rpoint);
  891.                   else new=check_4flo(hiszone,hisnet,hisnode,hispoint);
  892.                   if(new) goto MakeFloAnyway;
  893.               }
  894.             }
  895.             else if(rc<0) {
  896.                 fprintf(stderr,"Rename failed!\n");
  897.                 break;    /* Rename error; avoid fatal embrace */
  898.             }
  899.         }
  900.         do {    /* Loop through all outbound dirs if DOMAIN */
  901.         founddir=_dos_findnext(&d);
  902.     } while(!founddir && !(d.attrib & 16));
  903.     }
  904.     if(!fp) break;
  905.     if(feof(fp)) {        /* End of file...implicit END */
  906. DoneWithFile:            /* Terminate on END or big error */
  907.         fclose(fp);
  908.         fp=NULL;
  909.         sprintf(s,"%s\\*.?UT",outbound);    /* Find everybody left */
  910.         strcpy(arccmd,tempcmd);
  911.         type=alltype;
  912.         hiszone=myzone;
  913.         doingnet=doingzone=doingdomain=0;
  914.         printf("Default pass through default zone (%s)...\n",root);
  915.         strcpy(outbound,root);
  916.         goto OneMoreTime;
  917.     }
  918.   }
  919.   if(fp) fclose(fp);
  920.  
  921.   /* Display time of run */
  922.  
  923.   lastpos=(time(NULL)-starttime)/60L;
  924.   printf("Run time: %ld minutes %ld seconds\n",lastpos,(time(NULL)-starttime)-(lastpos*60L));
  925. }
  926.  
  927.  
  928.  
  929. void _cdecl deinit (void) {
  930.  
  931.     unlink("MAKEARC.RUN");    /* Get rid of marker file */
  932. }
  933.  
  934.  
  935.  
  936. void _fastcall say_error (long lastpos,FILE *fp) {
  937.  
  938.     char s[256];
  939.  
  940.     /* Give some info on obvious error encountered in config file */
  941.  
  942.     fseek(fp,lastpos,SEEK_SET);
  943.     if(!fgets(s,256,fp)) return;
  944.     stripcr(s);
  945.     fprintf(stderr,"ERROR line #%u:  `%s'\n\n",lines,s);
  946. }
  947.  
  948.  
  949.  
  950. char * _fastcall arcname (_word net,_word node) {
  951.  
  952.     /* Return outbound-style archive (bundle) filename */
  953.  
  954.     static char name[9];
  955.  
  956.     sprintf(name,"%04x%04x",mynet-net,mynode-node);
  957.     return name;
  958. }
  959.  
  960.  
  961. char * _fastcall filename (_word net,_word node) {
  962.  
  963.     /* Return outbound-style filename */
  964.  
  965.     static char name[9];
  966.  
  967.     sprintf(name,"%04x%04x",net,node);
  968.     return name;
  969. }
  970.  
  971.  
  972. void _fastcall next_name (char *p) {
  973.  
  974.     /* Increment archive name extension */
  975.  
  976.     strupr(p);
  977.     if(!strncmp(p,".MO",3)) strcpy(p,".TU1");
  978.     else if(!strncmp(p,".TU",3)) strcpy(p,".WE1");
  979.     else if(!strncmp(p,".WE",3)) strcpy(p,".TH1");
  980.     else if(!strncmp(p,".TH",3)) strcpy(p,".FR1");
  981.     else if(!strncmp(p,".FR",3)) strcpy(p,".SA1");
  982.     else if(!strncmp(p,".SA",3)) strcpy(p,".SU1");
  983.     else strcpy(p,".MO1");
  984. }
  985.  
  986.  
  987.  
  988. char * _fastcall fidodate (void) {  /* THIS IS THE RIGHT WAY, DAMMIT!!! */
  989.  
  990.  static char fdate[21];
  991.  time_t tt;
  992.  
  993. /* Sample output:  '26 Jul 89  06:23:47' */
  994.  
  995.  time(&tt);
  996.  strftime(fdate,20,"%d %b %y  %H:%M:%S",localtime(&tt));
  997.  return(fdate);
  998. }
  999.  
  1000.  
  1001.  
  1002. FILE * _fastcall analyze (char *file) {
  1003.  
  1004.     int handle;
  1005.     static FILE *pf;
  1006.  
  1007.     /* Opens config file, finds starting sched if any, returns handle */
  1008.  
  1009.     handle=sopen(file,O_RDONLY | O_TEXT,SH_DENYWR);
  1010.     if(handle==-1) goto OpenError;
  1011.  
  1012.     pf=fdopen(handle,"rt");
  1013.     if(pf==NULL) {
  1014. OpenError:
  1015.         fprintf(stderr,"\nCan't open control file \'%s\'\n",file);
  1016.         exit(5);
  1017.     }
  1018.     printf("\nReading control file \'%s\'...\n",file);
  1019.  
  1020.     if(*schedtag) {
  1021.         if(find_sched(pf,schedtag,0)) {
  1022.             printf("Processing schedule tag '%s'\n",schedtag);
  1023.             *schedtag=0;
  1024.         }
  1025.         else exit(10);
  1026.     }
  1027.     return (pf);
  1028. }
  1029.  
  1030.  
  1031. _word _fastcall makeflo (_word zone,_word net,_word node,_word point,char *sendfile,char type) {
  1032.  
  1033.     int handle;
  1034.     char s[133];
  1035.     char tries=0;
  1036.     int x;
  1037.  
  1038.     /* Create a .?LO file */
  1039.  
  1040.     if(type=='N' || type=='O') type='F';
  1041.     sprintf(s,"%s\\%04x%04x.%cLO",outbound,net,node,type);
  1042.     printf("Creating/appending flow attach `%s'...\n",s);
  1043. ReTry:
  1044.     handle=sopen(s,O_RDWR | O_BINARY | O_APPEND, SH_DENYWR);
  1045.     if(handle==-1) handle=creat(s,S_IWRITE);
  1046.     if(handle==-1) {
  1047.         if(tries++ < 9) {
  1048.             if(debug) printf("Can't access %s; retry #%hu\n",s,tries);
  1049.             goto ReTry;
  1050.         }
  1051.         fprintf(stderr,"\nCouldn't open `%s' (errno=%d)\n",s,errno);
  1052.         return 1;
  1053.     }
  1054.     lseek(handle,0L,SEEK_END);
  1055.     sprintf(s,"#%s\r\n",sendfile);
  1056.     x=strlen(s);
  1057.     if(write(handle,(void *)s,(unsigned int)x)<x) {
  1058.         close(handle);
  1059.         fprintf(stderr,"\nProblem writing to flow file...\n");
  1060.         return 1;
  1061.     }
  1062.     close(handle);
  1063.     return 0;
  1064. }
  1065.  
  1066.  
  1067.  
  1068. char _fastcall check_4flo (_word zone,_word net,_word node,_word point) {
  1069.  
  1070.     char s[133];
  1071.     struct find_t f;
  1072.  
  1073.     /* Quick and crude check for orphaned bundles */
  1074.  
  1075.     sprintf(s,"%s\\%04x%04x.?LO",outbound,net,node);
  1076.     if(_dos_findfirst(s,0,&f)) {
  1077. Orphan:
  1078.         if(debug || more) printf("Apparently orphaned bundle...\n");
  1079.         return 1;
  1080.     }
  1081.     if(f.size==0L) goto Orphan;
  1082.     return 0;
  1083. }
  1084.  
  1085.  
  1086.  
  1087. _word _fastcall makemessage (_word zone,_word net,_word node,_word point,char *sendfile,char type) {
  1088.  
  1089.     int handle;
  1090.     struct find_t f;
  1091.     static _word x=1;
  1092.     char s[133];
  1093.     register _word y;
  1094.     struct _msg msg;
  1095.     char tries=0;
  1096.  
  1097.     /* Make *.MSG attach */
  1098.  
  1099.     msg.attr = MSGLOCAL | MSGKILL | MSGFILE;
  1100.     strncpy(msg.subj,sendfile,72);
  1101.     msg.subj[71]=0;
  1102.     msg.dest=node;
  1103.     msg.dest_net=net;
  1104.     msg.orig=mynode;
  1105.     msg.orig_net=mynet;
  1106.     strcpy(msg.date,fidodate());
  1107.     strcpy(msg.from,"Attach Message");
  1108.     strcpy(msg.to,"Mail Processor");
  1109.     for(y=0;y<4;y++) msg.msg_filler[y]=0;
  1110.     msg.reply=0;
  1111.     msg.up=0;
  1112.     msg.times=0;
  1113.     msg.cost=0;
  1114.     sprintf(s,"%s\\%u.MSG",netdir,x);
  1115.     fprintf(stderr,"Creating damn file attach msg `%s'...\n",s);
  1116. ReTry:
  1117.     while(!_dos_findfirst(s,0,&f)) {
  1118.         x++;
  1119.         if(!x) {
  1120.             fprintf(stderr,"\nDamn Msg directory is full\n");
  1121.             exit(1);
  1122.         }
  1123.         sprintf(s,"%s\\%u.MSG",netdir,x);
  1124.     }
  1125.     handle=creat(s,S_IWRITE);
  1126.     if(handle==-1) {
  1127.         if(tries++<9) {
  1128.             if(debug) printf("Can't create %s; retry #%hu\n",s,tries);
  1129.             goto ReTry;
  1130.         }
  1131.         fprintf(stderr,"\nCouldn't open `%s'\n",s);
  1132.         exit(2);
  1133.     }
  1134.     setmode(handle,O_BINARY);
  1135.  
  1136.     write(handle,&msg,sizeof(struct _msg));
  1137.  
  1138.     sprintf(s,"\01MSGID: %u:%u/%01u.%01u %8.8s\r",myzone,mynet,mynode,mypoint,make_msgid());
  1139.     write(handle,s,strlen(s));           /* MSGID kludge */
  1140.  
  1141.     sprintf(s,"\01MSGTO: %u:%u/%01u.%01u\r",zone,net,node,point);
  1142.     write(handle,s,strlen(s));           /* MSGTO kludge */
  1143.  
  1144. /* 09/15/90 FLAGS info updated to sorta match that given by Odinn Sorenson */
  1145. /* 12/03/90 FLAGS info updated to match (maybe) FSC-0053 */
  1146.  
  1147.     write(handle,"\01FLAGS TFS XMA",11);   /* FIL? */
  1148.     if(type=='H') write(handle," HLD",5);
  1149.     if(type=='C') write(handle," CRA",6);  /* IMM? */
  1150. /*    if(type=='N' || type=='F' || type=='O') write(handle," NRM",5); */ /* ???? */
  1151.     if(type=='D') write(handle," DIR",7);
  1152.     write(handle,"\r",1);
  1153.  
  1154.     if(mypoint) {   /* Barforama stuff for backward (and I do mean backward) */
  1155.         sprintf(s,"\01FMPT %01u\r",mypoint);    /* compatibility */
  1156.         write(handle,s,strlen(s));
  1157.     }    /* FMPT kludge */
  1158.  
  1159.     if(point) {
  1160.         sprintf(s,"\01TOPT %01u\r",point);
  1161.         write(handle,s,strlen(s));
  1162.     }    /* TOPT kludge */
  1163.  
  1164.     if(zone!=myzone) {
  1165.         y=sprintf(s,"\01INTL %u:%u/%01u %u:%u/%01u\r",zone,net,node,myzone,mynet,mynode);
  1166.         write(handle,s,y);
  1167.     }    /* INTL kludge */
  1168.  
  1169.     sprintf(s,"\01PID: %s\r",PID_ID);
  1170.     write(handle,s,strlen(s));           /* PID kludge just for the hell of it */
  1171.     write(handle,"\0",1);               /* Null-terminate (couldn't hoit) */
  1172.  
  1173.     close(handle);
  1174.  
  1175.     return 0;
  1176. }
  1177.  
  1178.  
  1179. int _fastcall makearc (char *arcfile,char *pktfile,char *origpkt, char *outbound) {
  1180.  
  1181.     char level;
  1182.     char s[177];
  1183.     struct find_t f;
  1184.  
  1185.         /* Create/add to a bundle */
  1186.  
  1187.     if(stricmp(arccmd,"DON'T_ARCHIVE")) {    /* Kludge for not archiving w/ *.MSG attaches */
  1188.         sprintf(s,"%s %s %s",arccmd,arcfile,pktfile);
  1189.         if(debug || more) printf("To DOS: %s\n",s);
  1190.         level=spawnit(s);
  1191.         if(_dos_findfirst(arcfile,0,&f)) {
  1192. ArchiverError:
  1193.             fprintf(stderr,"\nArchive attempt failed!\n");
  1194.             origpkt[strlen(origpkt)-1]='!';
  1195.             printf("Renaming %s to %s\\%s\n",pktfile,outbound,origpkt);
  1196.             sprintf(s,"%s\\%s",outbound,origpkt);
  1197.             if(rename(pktfile,s)) return -1;
  1198.             return 1;
  1199.         }
  1200.         else if (f.size==0L) goto ArchiverError;
  1201.         if(!_dos_findfirst(pktfile,0,&f)) {
  1202.             printf("Archiver didn't kill packet.\n");
  1203.             if(!level) {
  1204.                 printf("  I will...\n");
  1205.                 unlink(pktfile);
  1206.             }
  1207.             else {
  1208.                 origpkt[strlen(origpkt)-1]='!';
  1209.                 printf("Renaming %s to %s\\%s...\n",pktfile,outbound,origpkt);
  1210.                 sprintf(s,"%s\\%s",outbound,origpkt);
  1211.                 if(rename(pktfile,s)) return -1;
  1212.                 return 1;
  1213.             }
  1214.         }
  1215.         return 0;
  1216.     }
  1217.  
  1218.     strcpy(arcfile,pktfile);    /* Now attach msg will reference bare
  1219.                                    packet name, not an archive */
  1220.     return 0;
  1221. }
  1222.